package com.shanwen.shopping.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanwen.shopping.R;
import com.shanwen.shopping.entity.GoodsClassify;

import java.util.List;

/**
 * Created by lex on 2017/10/9.
 */

public class CategoryAdapter extends BaseAdapter {

    private List<GoodsClassify> list;
    private Context context;


    public CategoryAdapter(Context context, List<GoodsClassify> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        ViewHolder holder = null;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(context).inflate(R.layout.item_good_category, null);
            holder.tvCategoryName = (TextView) v.findViewById(R.id.tvCategoryName);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.tvCategoryName.setText(list.get(position).getName());
        if (list.get(position).isSelected()) {
            holder.tvCategoryName.setBackgroundColor(Color.parseColor("#ffffff"));
        } else {
            holder.tvCategoryName.setBackgroundColor(Color.parseColor("#e3e3e3"));
        }
        return v;
    }

    class ViewHolder {
        TextView tvCategoryName;
    }
}
